package contegor.scire.core.queries;

import contegor.scire.core.Concept;
import contegor.scire.core.Container;
import contegor.scire.core.Id;
import contegor.scire.core.IdFragment;
import contegor.scire.core.Version;

/**
 * {@link Query} that returns {@link Concept}s with the {@link Id}s given to the constructor.
 *
 * @version $Revision$
 * @author  Héctor Cirbián Pousa ($Author$)
 */
@Version("$Id$")
public class GetConcepts extends Query<Concept> {
  private static final long serialVersionUID = -423582669472666504L;

  protected IdFragment[] ids;

  public GetConcepts(Id id) {
    super(id.getParentId());
    this.ids = new IdFragment[] {id.getLastIdFragment()};
  }

  public GetConcepts(Id targetContainerId, IdFragment ... ids) {
    super(targetContainerId);
    this.ids = ids;
  }

  @Override
  public void process(Container targetContainer) {
    for (IdFragment id: ids) {
      Concept c = targetContainer.getConcept(id);
      if ((c != null) && c.isVisibleTo(this.taskId.getTransactionId()))
        this.returnPoint.manage(this.taskId, c);
    }
  }
}
